import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store = new Vuex.Store({
    state: {
        userInfo:uni.getStorageSync('userInfo')||null,
        hasLogin: uni.getStorageSync('token')?true:false,
    },
    mutations: {
		// 更新用户数据
		upDataUserinfo(state, provider) {
			state.userInfo = provider;
			state.hasLogin = true;
			uni.setStorageSync('userInfo',provider) 
		},
		//退出登录
		logout(state) {
			state.hasLogin = false;
			state.userInfo = {};
			uni.removeStorageSync('userInfo')
			uni.removeStorageSync('token') 
		},
		historyUser(state, provider) {
			//缓存为历史登录用户
			uni.setStorageSync('historyUser',provider);
		},
    },
    actions:{
        setUserData:function(context,obj){
            context.commit('upDataUserinfo',obj)
        },
		logout:function(context){
		    context.commit('logout')
		},
		setHistoryUser:function(context,obj){
		    context.commit('historyUser',obj)
		}
    },
})

export default store